package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.BasePageQuery;
import com.team.recruitment_management_system.pojo.dto.job.AddJobInfoDto;
import com.team.recruitment_management_system.pojo.dto.job.ChangeJobInfoDto;
import com.team.recruitment_management_system.pojo.dto.job.JobPageQuery;
import com.team.recruitment_management_system.pojo.vo.job.JobInfoVo;
import com.team.recruitment_management_system.security.OperationLogAnnotation;
import com.team.recruitment_management_system.service.JobService;
import com.team.recruitment_management_system.util.result.PageResult;
import com.team.recruitment_management_system.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/job")
@Tag(name = "职位模块")
public class JobController {
    @Autowired
    private JobService jobService;

    @PostMapping("/one")
    @Operation(summary = "添加job", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "插入", operDesc = "添加job")
    public Result<Void> addJobInfo(@RequestBody @Validated AddJobInfoDto addJobInfoDto) {
        return jobService.addJobInfo(addJobInfoDto);
    }

    @PutMapping("/one")
    @Operation(summary = "修改job", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "修改", operDesc = "修改job")
    public Result<Void> changeJobInfo(@RequestBody @Validated ChangeJobInfoDto changeJobInfoDto) {
        return jobService.changeJobInfo(changeJobInfoDto);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "根据Id删除job", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "查询", operDesc = "根据Id删除job")
    public Result<Void> deleteJobById(@PathVariable int id) {
        return jobService.deleteJobById(id);
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "求职者根据Id获取job")
    public Result<JobInfoVo> seeketGetJobInfoById(@PathVariable int id) {
        return jobService.getJobInfoById(id, true, false);
    }

    @GetMapping("/other/{id}")
    @Operation(summary = "管理员根据Id获取job", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "查询", operDesc = "管理员根据Id获取job")
    public Result<JobInfoVo> getJobInfoById(@PathVariable int id) {
        return jobService.getJobInfoById(id, false, false);
    }

    @GetMapping("/hr/{id}")
    @Operation(summary = "hr根据Id获取job", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "查询", operDesc = "hr根据Id获取job")
    public Result<JobInfoVo> hrGetJobInfoById(@PathVariable int id) {
        return jobService.getJobInfoById(id, false, true);
    }

    @GetMapping("/company/{id}")
    @Operation(summary = "根据公司Id获取job分页", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<JobInfoVo> hrGetJobInfoById(@PathVariable int id, BasePageQuery basePageQuery) {
        return jobService.getJobInfoByCompanyId(id,basePageQuery);
    }

    @GetMapping("/hr/more")
    @Operation(summary = "hr获取职位分页", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "查询", operDesc = "hr获取职位分页")
    public PageResult<JobInfoVo> hrGetJobInfoPage(JobPageQuery jobPageQuery, @RequestHeader String Authorization) {
        return jobService.hrGetJobInfoPage(jobPageQuery, Authorization);
    }

    @GetMapping("/other/more")
    @Operation(summary = "管理员获取职位分页", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "职位模块", operType = "查询", operDesc = "管理员获取职位分页")
    public PageResult<JobInfoVo> otherGetJobInfoPage(JobPageQuery jobPageQuery) {
        return jobService.otherGetJobInfoPage(jobPageQuery);
    }

    @GetMapping("/more")
    @Operation(summary = "求职者获取职位分页")
    public PageResult<JobInfoVo> seekerGetJobInfoPage(JobPageQuery jobPageQuery) {
        return jobService.seekerGetJobInfoPage(jobPageQuery);
    }

    @GetMapping("/hot")
    @Operation(summary = "求职者获取热门职位")
    public Result<List<JobInfoVo>> getHotJob() {
        return jobService.getHotJob();
    }
}
